﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;

namespace DC2010_Editor
{
    [Description("Glass style button control."), ToolboxItem(true)]
    public class CrystalButton : CrystalButtonBase
    {
        // Fields
        private Color a;
        private Color b;
        private TextImageRelation c;
        private ContentAlignment d;
        private StringFormat ee = new StringFormat();
        private Image _image;
        private Rectangle g;
        private Rectangle h;

    // Methods
        public CrystalButton()
        {
            this.TextAlign = ContentAlignment.MiddleCenter;
            this.TextImageRelation = TextImageRelation.ImageBeforeText;
            this.BackColor = Color.LightGray;

            this.HighlightColor = Color.Gray;
            this.PushedColor = Color.Gray;
        }

        private void XYZ()
        {
            this.XYZ(false);
        }

        private void XYZ(bool A_0)
        {
            int x = 2;
            if (A_0)
            {
                base.Invalidate();
            }
            Rectangle rectangle = new Rectangle(x, x, base.Width - (2 * x), base.Height - (2 * x));
            if (this._image == null)
            {
                this.g = Rectangle.Empty;
                this.h = rectangle;
            }
            else
            {
                int width = Math.Min(rectangle.Width, this._image.Width);
                int height = Math.Min(rectangle.Height, this._image.Height);
                this.g = new Rectangle(rectangle.Left, rectangle.Top, width, height);
                if (((this.Text == null) || ((this.Text != null) && (this.Text == string.Empty))) || (this.c == TextImageRelation.Overlay))
                {
                    this.g.Offset((rectangle.Width / 2) - (width / 2), (rectangle.Height / 2) - (height / 2));
                    this.h = (this.c == TextImageRelation.Overlay) ? rectangle : Rectangle.Empty;
                }
                else
                {
                    switch (this.c)
                    {
                        case TextImageRelation.ImageAboveText:
                            this.g.Offset((rectangle.Width / 2) - (width / 2), 0);
                            this.h = new Rectangle(rectangle.Left, this.g.Bottom + x, rectangle.Width, (rectangle.Height - this._image.Height) - x);
                            return;

                        case TextImageRelation.TextAboveImage:
                            this.g.Offset((rectangle.Width / 2) - (width / 2), rectangle.Height - height);
                            this.h = new Rectangle(rectangle.Left, rectangle.Top, rectangle.Width, (rectangle.Height - this._image.Height) - x);
                            break;

                        case (TextImageRelation.TextAboveImage | TextImageRelation.ImageAboveText):
                            break;

                        case TextImageRelation.ImageBeforeText:
                            this.g.Offset(0, (rectangle.Height / 2) - (height / 2));
                            this.h = new Rectangle(this.g.Right + x, rectangle.Top, (rectangle.Width - this.g.Width) - x, rectangle.Height);
                            return;

                        case TextImageRelation.TextBeforeImage:
                            this.g.Offset(rectangle.Width - width, (rectangle.Height / 2) - (height / 2));
                            this.h = new Rectangle(rectangle.Left, rectangle.Top, (rectangle.Width - this._image.Width) - x, rectangle.Height);
                            return;

                        default:
                            return;
                    }
                }
            }
        }

        protected override void OnResize(EventArgs e)
        {
            this.XYZ(true);
            base.OnResize(e);
        }

        protected override void OnTextChanged(EventArgs e)
        {
            this.XYZ(true);
            base.OnTextChanged(e);
        }

        protected override void PaintButton(Graphics g)
        {
            RectangleF bounds = new RectangleF(0f, 0f, (float)base.Size.Width, (float)base.Size.Height);
            if (MouseIsPressed)
            {
                CrystalPaint.DrawPushedButtonHighlight(g, this.PushedColor, this.HighlightColor, CrystalPaint.RenderMode.HighQuality, bounds, base.FadePercentage);
            }
            else
            {
                if ((this.BackColor != base.Parent.BackColor) && (this.BackColor != Color.Transparent))
                {
                    CrystalPaint.DrawButtonHighlight(g, this.BackColor, Color.Transparent, bounds, CrystalPaint.RenderMode.HighQuality, 1f);
                }
                if (base.FadePercentage != 0f)
                {
                    CrystalPaint.DrawButtonHighlight(g, this.HighlightColor, this.PushedColor, bounds, CrystalPaint.RenderMode.HighQuality, base.FadePercentage);
                }
            }
            if (this._image != null)
            {
                if (!base.Enabled)
                {
                    ToolStripRenderer.CreateDisabledImage(this._image);
                }
                g.DrawImage(this._image, this.g);
            }
            g.DrawString(this.Text, this.Font, new SolidBrush(this.ForeColor), this.h, this.ee);
        }

        [Browsable(true), DefaultValue(typeof(Color), "255, 213, 70"), Description("The Color of a highlighted item.")]
        public Color HighlightColor
        {
            get
            {
                return this.b;
            }
            set
            {
                if (this.b != value)
                {
                    this.b = value;
                    base.Invalidate();
                }
            }
        }

        [Browsable(true), Category("Appearance")]
        public Image Image
        {
            get
            {
                return this._image;
            }
            set
            {
                this._image = value;
                this.XYZ(true);
            }
        }

        protected Rectangle ImageBounds
        {
            get
            {
                return this.g;
            }
        }



        [DefaultValue(typeof(Color), "249, 145, 42"), Browsable(true), Description("The Color of a selected item.")]
        public Color PushedColor
        {
            get
            {
                return this.a;
            }
            set
            {
                //if (value == Color.Empty)
                //{
                //    throw new Exception("Value can not be Empty Color.");
                //}
                if (this.a != value)
                {
                    this.a = value;
                    base.Invalidate();
                }
            }
        }



        [DefaultValue(typeof(ContentAlignment), "MiddleCenter"), Browsable(true), Category("Appearance")]
        public ContentAlignment TextAlign
        {
            get
            {
                return this.d;
            }
            set
            {
                this.d = value;
                switch (value)
                {
                    case ContentAlignment.TopLeft:
                        this.ee.LineAlignment = StringAlignment.Near;
                        this.ee.Alignment = StringAlignment.Near;
                        goto Label_0161;

                    case ContentAlignment.TopCenter:
                        this.ee.LineAlignment = StringAlignment.Near;
                        this.ee.Alignment = StringAlignment.Center;
                        goto Label_0161;

                    case (ContentAlignment.TopCenter | ContentAlignment.TopLeft):
                        goto Label_0161;

                    case ContentAlignment.TopRight:
                        this.ee.LineAlignment = StringAlignment.Near;
                        this.ee.Alignment = StringAlignment.Far;
                        goto Label_0161;

                    case ContentAlignment.MiddleLeft:
                        this.ee.LineAlignment = StringAlignment.Center;
                        this.ee.Alignment = StringAlignment.Near;
                        goto Label_0161;

                    case ContentAlignment.MiddleCenter:
                        this.ee.LineAlignment = StringAlignment.Center;
                        this.ee.Alignment = StringAlignment.Center;
                        goto Label_0161;

                    case ContentAlignment.MiddleRight:
                        this.ee.LineAlignment = StringAlignment.Center;
                        this.ee.Alignment = StringAlignment.Far;
                        goto Label_0161;

                    case ContentAlignment.BottomLeft:
                        this.ee.LineAlignment = StringAlignment.Far;
                        this.ee.Alignment = StringAlignment.Near;
                        goto Label_0161;

                    case ContentAlignment.BottomCenter:
                        this.ee.LineAlignment = StringAlignment.Far;
                        this.ee.Alignment = StringAlignment.Center;
                        break;

                    case ContentAlignment.BottomRight:
                        this.ee.LineAlignment = StringAlignment.Far;
                        this.ee.Alignment = StringAlignment.Far;
                        goto Label_0161;
                }
            Label_0161:
                base.Invalidate();
            }
        }



        protected Rectangle TextBounds
        {
            get
            {
                return this.h;
            }
        }



        protected StringFormat TextFormat
        {
            get
            {
                return this.ee;
            }
        }



        [DefaultValue(typeof(TextImageRelation), "ImageAboveText"), Browsable(true), Category("Appearance")]
        public TextImageRelation TextImageRelation
        {
            get
            {
                return this.c;
            }
            set
            {
                this.c = value;
                this.XYZ(true);
            }
        }
 

 

 

 

 

 


 

 


 

 

 

 


 

 


 

 





    }
}
